package com.music.service.impl;

import com.music.dao.SongMapper;
import com.music.entity.Song;
import com.music.service.TopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;
@Slf4j
@Service
public class TopServiceImpl implements TopService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private SongMapper songMapper;

    @PostConstruct
    @Override
    public void catchSongToRedis() {
        log.debug("++++++++++++++++");

        Boolean existTodaySong=redisTemplate.hasKey("todaySong");
        if(existTodaySong){
            redisTemplate.delete("todaySong");
        }
        Song s=new Song();
        List<Song> list=songMapper.SelectByCondition(s);
        for(Song song:list){
            redisTemplate.opsForList().rightPush("todaySong",song);
        }
    }
}
